{include file="public/header" /}
<link rel="stylesheet" href="/static/index/css/merchant.css?v=<?php echo time();?>">

<body class="bgc hide-top">
<div class="pro-list-search">
    <i class="layui-icon layui-icon-left"  onclick="history.go(-1)"></i>
    <div class="rgt">
        <img src="/static/index/img/icon43.png" alt="">
        <input type="text" class="keyword" placeholder="请输入商品名称搜索" value="{$keyword?:''}">
        <p class="flex-center search_bt">搜索</p>
    </div>
</div>
<div class="tpl_list"></div>
<div class="add_foot" onclick="load_href('{:url(\'merchant/add\')}',2)">添加商品</div>
<script id="template" type="text/html">
    {{# if(d.data.length > 0){ }}
    <ul class="merchant-list">
        {{# for(var i = 0; i < d.data.length; i++){ }}
        <li>
            <div class="layui-row">
                <div class="layui-col-xs3">
                    <img lay-src="{{d.data[i].icon}}" src="{{d.data[i].icon}}" alt="">
                </div>
                <div class="layui-col-xs9">
                    <div class="flextitle">
                        <p class="multi" style="width: 100% !important;">{{d.data[i].title}}</p>
                        <p class="price">￥<span>{{d.data[i].vip_price}}</span><span>￥{{d.data[i].price}}</span></p>
                    </div>
                </div>
                <div class="layui-col-xs12 btnaniu">
                    <a class="editbtn" onclick="load_href('{:url(\'merchant/edit\')}?id={{d.data[i].id}}',2)"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="delbtn" onclick="del({{d.data[i].id}});"><i class="layui-icon layui-icon-delete"></i>删除</a>
                    {{# if(d.data[i].is_audit == 2){ }}
                        {{# if (d.data[i].status == 0) { }}
                            <a class="delbtn" style=" margin-right: 15px;" onclick="racks({{d.data[i].id}},1);">上架</a>
                        {{# }else{ }}
                            <a class="delbtn" style=" margin-right: 15px;" onclick="racks({{d.data[i].id}},2);">下架</a>
                        {{# } }}
                    {{# } }}
                </div>
            </div>
        </li>
        {{# } }}
    </ul>
    {{# }else { }}
    <div class="pro-list-data">
        <img src="/static/index/img/icon44.png" alt="">
        <p>暂无搜索结果</p>
    </div>
    {{# } }}
</script>

</body>
{include file="public/footer"/}
<script>
    $(function () {
        var end = '{$keyword?:""}' ? '没有更多了' : '没有更多了';
        getFlow(1, "{:url('merchant/getShopList')}?keyword={$keyword?:''}", 'template', end);

        $(".search_bt").click(function () {
            var keyword = $(".keyword").val();
            if (!keyword) {
                layer.msg('请填写要搜索商品名称');
                return false;
            }
            $(".tpl_list").empty();
            getFlow(1, "{:url('merchant/getShopList')}?keyword=" + keyword, 'template', end);
        });
    })
    function del(id){
        layer.confirm('确认要删除商品吗？', {title: '请确认'}, function () {
            common.load()
            $.ajax({
                type: 'POST',
                url: '{:url("merchant/del")}',
                data: {id: id},
                dataType: "json",
                success: function (data) {
                    layer.closeAll;
                    layer.msg(data.msg);
                    if (data.code == 1) {
                        $(".tpl_list").empty();
                        getFlow(1, "{:url('merchant/getShopList')}?keyword={$keyword?:''}", 'template', '没有更多了');
                    }
                }
            });
        });
    }
    
    function racks(id,type){
        layer.confirm('确认要'+(type == 1 ? "上架" : "下架")+'商品吗？', {title: '请确认'}, function () {
            common.load()
            $.ajax({
                type: 'POST',
                url: '{:url("merchant/racks")}',
                data: {id: id,type:type},
                dataType: "json",
                success: function (data) {
                    layer.closeAll;
                    layer.msg(data.msg);
                    if (data.code == 1) {
                        $(".tpl_list").empty();
                        getFlow(1, "{:url('merchant/getShopList')}?keyword={$keyword?:''}", 'template', '没有更多了');
                    }
                }
            });
        });
    }
</script>
</html>